package com.mo.bio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 线程池也无法解决：阻塞
 */
public class ServerSocketThreadTest {
    public static void main(String[] args) throws IOException {
        //telnet localhost 9000
        //ctrl+]
        //send 数据
        ServerSocket socket = new ServerSocket(9000);
        Socket accept = socket.accept();
        new Thread(()->{
            try {
                System.out.println("等待连接！");
                handler(accept);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }).start();

    }

    static  void handler(Socket accept) throws IOException {
        byte[] bytes = new byte[1024];
        int read = accept.getInputStream().read(bytes);
        while (read !=-1){
            System.out.println(new String(bytes,0,read));
        }

    }

}
